package com.nit.netty.worker;

import com.nit.netty.bean.invoker.NettyInterfaceInvoker;
import com.nit.netty.sender.RequestSender;

import java.util.concurrent.*;

/**
 * @Author: whb
 * @Description:
 * @CreateTime: 2020/8/21 13:54
 */
public class NettyThreadPool {

    /**
     * @Description: 单例模式
     */
    private static final class SINGLETON {
        private static int coreSize = 5;
        private static int maxSize = 8;
        private static int keepAliveTime = 0;
        private static TimeUnit timeUnit = TimeUnit.SECONDS;
        private static BlockingQueue<Runnable> blockingQueue = new ArrayBlockingQueue<>(100);
        private static final ThreadPoolExecutor pool = new ThreadPoolExecutor(coreSize, maxSize,
                keepAliveTime, timeUnit, blockingQueue);

        public static Future submit(Runnable runnable) throws Exception {
            return pool.submit(runnable);
        }
    }

    public static ThreadPoolExecutor getInstance() {
        return SINGLETON.pool;
    }

}
